<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: Import Reconstruction</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../d3/d81/tutorial_contrib_root.html">Tutorials for contrib modules</a></li><li class="navelem"><a class="el" href="../../de/d7c/tutorial_table_of_content_sfm.html">Structure From Motion</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Import Reconstruction </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h2>Goal </h2>
<p>In this tutorial you will learn how to import a reconstruction from a given file obtained with Bundler [1]:</p>
<ul>
<li>Load a file containing a set of cameras and 3D points.</li>
<li>Show obtained results using Viz.</li>
</ul>
<h2>Code </h2>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d3/df9/sfm_8hpp.html">opencv2/sfm.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d0/d7e/viz_8hpp.html">opencv2/viz.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span>std;</div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d2/d75/namespacecv.html">cv</a>;</div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../db/db0/namespacecv_1_1sfm.html">cv::sfm</a>;</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> help() {</div><div class="line">  cout</div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;\n---------------------------------------------------------------------------\n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot; This program shows how to import a reconstructed scene in the \n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot; OpenCV Structure From Motion (SFM) module.\n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot; Usage:\n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;        example_sfm_import_reconstruction &lt;path_to_file&gt;\n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot; where: file_path is the absolute path file into your system which contains\n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;        the reconstructed scene. \n&quot;</span></div><div class="line">      &lt;&lt; <span class="stringliteral">&quot;---------------------------------------------------------------------------\n\n&quot;</span></div><div class="line">      &lt;&lt; endl;</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[])</div><div class="line">{</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> ( argc != 2 ) {</div><div class="line">    help();</div><div class="line">    exit(0);</div><div class="line">  }</div><div class="line"></div><div class="line"></div><div class="line">  vector&lt;Mat&gt; Rs, Ts, Ks, points3d;</div><div class="line">  <a class="code" href="../../d2/da3/group__io.html#ga10a93a70917b83ac7929f7cc40e5365b">importReconstruction</a>(argv[1], Rs, Ts, Ks, points3d, <a class="code" href="../../d2/da3/group__io.html#ggacca2d8c213e2e8b9f83bb36b083fbd91abf49ab84b44c1c6bec4b68b268001941">SFM_IO_BUNDLER</a>);</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line">  <a class="code" href="../../d6/d32/classcv_1_1viz_1_1Viz3d.html">viz::Viz3d</a> window(<span class="stringliteral">&quot;Coordinate Frame&quot;</span>);</div><div class="line">             window.setWindowSize(<a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(500,500));</div><div class="line">             window.setWindowPosition(<a class="code" href="../../dc/d84/group__core__basic.html#ga1e83eafb2d26b3c93f09e8338bcab192">Point</a>(150,150));</div><div class="line">             window.setBackgroundColor(); <span class="comment">// black by default</span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line">  vector&lt;Vec3d&gt; point_cloud;</div><div class="line">  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; points3d.size(); ++i){</div><div class="line">    point_cloud.push_back(<a class="code" href="../../dc/d84/group__core__basic.html#gab9e0ab642a3e01742916763173b72232">Vec3f</a>(points3d[i]));</div><div class="line">  }</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line">  vector&lt;Affine3d&gt; path;</div><div class="line">  <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; Rs.size(); ++i)</div><div class="line">    path.push_back(<a class="code" href="../../dd/d99/classcv_1_1Affine3.html">Affine3d</a>(Rs[i], Ts[i]));</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line">  <a class="code" href="../../db/d82/classcv_1_1viz_1_1WCloud.html">viz::WCloud</a> cloud_widget(point_cloud, viz::Color::green());</div><div class="line">  <a class="code" href="../../d0/da3/classcv_1_1viz_1_1WTrajectory.html">viz::WTrajectory</a> trajectory(path, viz::WTrajectory::FRAMES, 0.5);</div><div class="line">  <a class="code" href="../../da/d80/classcv_1_1viz_1_1WTrajectoryFrustums.html">viz::WTrajectoryFrustums</a> frustums(path, <a class="code" href="../../dc/d84/group__core__basic.html#ga392bb4f8a6b9e0dde07f31dc28e73319">Vec2f</a>(0.889484, 0.523599), 0.5,</div><div class="line">                                    viz::Color::yellow());</div><div class="line"></div><div class="line">  window.showWidget(<span class="stringliteral">&quot;point_cloud&quot;</span>, cloud_widget);</div><div class="line">  window.showWidget(<span class="stringliteral">&quot;cameras&quot;</span>, trajectory);</div><div class="line">  window.showWidget(<span class="stringliteral">&quot;frustums&quot;</span>, frustums);</div><div class="line"></div><div class="line"></div><div class="line">  cout &lt;&lt; endl &lt;&lt; <span class="stringliteral">&quot;Press &#39;q&#39; to close each windows ... &quot;</span> &lt;&lt; endl;</div><div class="line"></div><div class="line">  window.spin();</div><div class="line"></div><div class="line">  <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --><h2>Results </h2>
<p>The following picture shows a reconstruction from la <em>Sagrada Familia</em> (BCN) using dataset [2].</p>
<div class="image">
<img src="../../import_sagrada_familia.png" alt="import_sagrada_familia.png"/>
</div>
<p>[1] <a href="http://www.cs.cornell.edu/~snavely/bundler">http://www.cs.cornell.edu/~snavely/bundler</a></p>
<p>[2] Penate Sanchez, A. and Moreno-Noguer, F. and Andrade Cetto, J. and Fleuret, F. (2014). LETHA: Learning from High Quality Inputs for 3D Pose Estimation in Low Quality Images. Proceedings of the International Conference on 3D vision (3DV). <a href="http://www.iri.upc.edu/research/webprojects/pau/datasets/sagfam">URL</a> </p>
</div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:39 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
